package com.api.hg.scheld;

import com.api.hg.model.gbzcException;
import com.api.hg.model.swException;
import com.api.hg.model.uf_gbzcdp;
import com.api.hg.service.GbSwExceptionBaseService;
import com.api.hg.service.SwExceptionBaseService;
import com.api.hg.service.uf_gbzcdpBaseService;
import com.api.sw.duban.annotation.Field;
import com.api.sw.duban.util.LogTool;
import weaver.conn.RecordSet;
import weaver.formmode.setup.ModeRightInfo;
import weaver.general.GCONST;
import weaver.general.Util;
import weaver.interfaces.schedule.BaseCronJob;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//com.api.hg.scheld.GbSwExceptionConjob  亏

/**
 * 关保状态
 * 4	已调拨
 * 5	已差错更正
 * 6	已报损报废
 * 7	减少中
 * 8	已减少
 * 0	在库
 * 1	在用
 * 2	分配中
 * 3	调拨中
 * 9    报损报废中
 * 实物资产状态
 * 8	已转出
 * 0	在库
 * 1	已领用
 *  * 2	报废确认中
 *  * 3	已借用
 *  * 4	转出确认中
 *  * 5	调拨确认中
 *  * 6	借用确认中
 *  * 7	已减账
 */
public class GbSwExceptionConjob extends BaseCronJob {
    private final static LogTool log = new LogTool("/log/assetlog/luolf/GbSwExceptionConjob",false);
    public  static void  main(String args[]) throws Exception {
        String rootPath = "D:\\WEAVER\\ecology\\";
        GCONST.setRootPath(rootPath);
        GCONST.setServerName("ecology");
        GbSwExceptionConjob job = new GbSwExceptionConjob();
        //job.execute();
        job.setZsbfl();
        
    }

    @Override
    public void execute() {
        //bengin conjob\
        synchronized (GbSwExceptionConjob.class){
            compareGBToSW();
            compareGBToSW_vali();

            RecordSet del = new RecordSet();
            boolean delGbyc = del.execute("delete from uf_uf_gbxtzczmxxexc  where gbzcid in ( select kpwybs from uf_gbxtzczmxx gb  where  gbzcid=gb.kpwybs and gb.kpzt not in (0,1,2,3))");
            log.writeLog(delGbyc?"删除关保异常表中对应不需要数据成功"+del.getCounts():"删除关保异常表中对应不需要数据失败");

            RecordSet up = new RecordSet();
            boolean upGbycsybm = up.execute("update uf_uf_gbxtzczmxxexc set sybm=(select sybm from uf_gbxtzczmxx where kpwybs=gbzcid)");
            if(upGbycsybm){
                log.writeLog("先更新关保异常表的使用部门");
                setZsbfl();
                updateGbyc();
            }

            boolean upGbyckph = up.execute("update uf_uf_gbxtzczmxxexc set kph=uf_gbxtzczmxx.kph from uf_gbxtzczmxx  where uf_gbxtzczmxx.kpwybs=gbzcid");
            if(upGbyckph){
                log.writeLog("更新关保异常表的卡片号成功");
            }
            System.err.println("-------------------------");
        }
    }

    /**
     * 关保对碰实物  不匹配写入关保资产异常表
     */
    public void compareGBToSW(){
        iniDate();
        int max=10;//
        GbSwExceptionBaseService SwExceptionBaseService=new GbSwExceptionBaseService();
        RecordSet re=new RecordSet();
        //String  sql=" select  a.* from uf_gbxtzczmxx a  where len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0 and " +
                //" not exists (select 1  from uf_swzczmxx b where ((b.kpwybh=a.kpwybs or b.kph=a.kpwybs ) and len(isnull(b.kpwybh,''))>0) or ((b.kpwybh=a.kph or b.kph=a.kph ) and len(isnull(b.kph,''))>0)    ) ";
        String sql="select * from uf_gbxtzczmxx a1,( \n" +
                   " select kpwybs,sxrq from( \n" +
                   " select kpwybs,sxrq,ROW_NUMBER() over(partition by kpwybs order by sxrq desc) RowNum from ( \n" +
                   //" select  * from uf_gbxtzczmxx a  where isnull(dj,1000)>=1000 and len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0 and len( isnull(sxrq,''))>0 and isnull(kpzt,-1) in (0,1,2,3) and len(isnull(a.dyswzc,''))=0 and" +
                //" select  * from uf_gbxtzczmxx a  where len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0 and len( isnull(sxrq,''))>0 and isnull(kpzt,-1) in (0,1,2,3) and len(isnull(a.dyswzc,''))=0 and" +
                " select  * from uf_gbxtzczmxx a  where len(isnull(kpwybs,''))>0 and isnull(sybm,0)>0  and isnull(kpzt,-1) in (0,1,2,3) and len(isnull(a.dyswzc,''))=0  \n" +
                " and (mldm in ('1030104','1030105','1030107','103060401','103060101','103060102','103060103','103060104','103060199','30105','10204','1030605') \n"+
                " or (mldm in ('103019903','103019904') and gdzcbm not like '%执法记录仪工作站%' and gdzcbm not like '%无盘工作站%')" +
                " or (mldm in ('1030106') and gdzcbm not like '%终端%' and gdzcbm not like '%电子%'  and gdzcbm not like '%执法%' ) ) \n"+
                " and not exists (select 1  from uf_swzczmxx b where ((b.kpwybh=a.kpwybs or b.xzgbxtzc=a.kpwybs or b.xzgbxtzc=a.kpwybs) and len(isnull(b.kpwybh,''))>0) \n" +
                " and isnull(b.zczt,-1) in (0,1,2,4,5,7) )     )  a  ) b where RowNum=1 ) b1 \n" +
                " where a1.kpwybs=b1.kpwybs AND a1.kph NOT LIKE '%57J%' ";
               // " where a1.kpwybs=b1.kpwybs and a1.sxrq=b1.sxrq";
        log.writeLog(sql);
        re.execute(sql);
        List<Object> business =new ArrayList<Object>() ;
        List<Map<String, Object>> listMap=new ArrayList<Map<String, Object>>();
        gbzcException gbzcException=null;

        RecordSet s1 = new RecordSet();
        RecordSet u1 = new RecordSet();
        while(re.next()){
            gbzcException=new gbzcException();
            String kpwybs=Util.null2String(re.getString("kpwybs"));//卡片唯一标识
            gbzcException.setKpwybs(kpwybs);
            String kph=Util.null2String(re.getString("kph"));//卡片号
            gbzcException.setKph(kph);
            String mldm=Util.null2String(re.getString("mldm"));//目录代码
            gbzcException.setMldm(mldm);
            String mlmc=Util.null2String(re.getString("mlmc"));//目录名称
            gbzcException.setMlmc(mlmc);
            String gdzcbm=Util.null2String(re.getString("gdzcbm"));//固定资产编码
            gbzcException.setGdzcbm(gdzcbm);
            String gdzcmc=Util.null2String(re.getString("gdzcmc"));//固定资产名称
            gbzcException.setGdzcmc(gdzcmc);
            String ggxh=Util.null2String(re.getString("ggxh"));//规格型号
            gbzcException.setGgxh(ggxh);
            String pp=Util.null2String(re.getString("pp"));//	品牌
            gbzcException.setPp(pp);
            double dj=Util.getDoubleValue(re.getString("dj"), 0);//单价
            gbzcException.setDj(dj);
            int zcly=Util.getIntValue(re.getString("zcly"),-1);//资产来源
            gbzcException.setZcly(zcly);
            int kpzt=Util.getIntValue(re.getString("kpzt"),-1);//卡片状态
            gbzcException.setKpzt(kpzt);
            String sxrq=Util.null2String(re.getString("sxrq"));//	生效日期
            gbzcException.setSxrq(sxrq);
            String qdrq=Util.null2String(re.getString("qdrq"));//取得日期
            gbzcException.setQdrq(qdrq);
            String jssj=Util.null2String(re.getString("jssj"));//减少时间
            gbzcException.setJssj(jssj);
            int sybm=Util.getIntValue(re.getString("sybm"),-1);//使用部门
            gbzcException.setSybm(sybm);
            int syr=Util.getIntValue(re.getString("syr"),-1);//使用人
            gbzcException.setSyr(syr);
            String cfdd=Util.null2String(re.getString("cfdd"));//存放地点
            gbzcException.setCfdd(cfdd);
            String bz=Util.null2String(re.getString("bz"));//	备注
            gbzcException.setBz(bz);
            String id=Util.null2String(re.getString("id"));//	id

            String gbzcid=kpwybs;//Util.null2String(re.getString("id"));//	关保资产ID
            if(checkVali(kpwybs)){
                log.writeLog("compareGBToSW 存在--->"+kph);
                continue;
            }
            gbzcException.setGbzcid(gbzcid);
            gbzcException.setGbbid(id);//额外存储关保建模表id
            //swException.setSfpk(0);//
            business.add(gbzcException);

            //Object[] param2=new Object[2];
            //String sql12="update uf_gbxtzczmxx  set sfpk=? where id=?";
            //param2[0]=1;
            //param2[1]=gbzcid;
            //Map<String,Object> sqlmap2=new HashMap<>();
            //sqlmap2.put("sql",sql12);
            //sqlmap2.put("params",param2);
            //listMap.add(sqlmap2);

            //if(business.size()==max){
            //开始写入
            String mess=SwExceptionBaseService.getObjMapList(business,null);
            if(!"".equals(mess)){
                log.writeLog(business.toString());
            }
            //清空business
            business.clear();
            //}
        }
        if(business.size()>0){
            String mess=SwExceptionBaseService.getObjMapList(business,null);
            if(!"".equals(mess)){
                log.writeLog(mess+"--->"+business.toString());
            }
        }
        setQx();
    }
    //对碰时判断下当前有没有新的实物关联了关保资产，有则更新关保异常表和关保资产建模表
    public void compareGBToSW_vali(){
        iniDate();
        int max=10;//
        GbSwExceptionBaseService SwExceptionBaseService=new GbSwExceptionBaseService();
        RecordSet re=new RecordSet();
        //String  sql=" select  a.* from uf_gbxtzczmxx a  where len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0 and " +
                //"  exists (select 1  from uf_swzczmxx b where ((b.kpwybh=a.kpwybs or b.kph=a.kpwybs ) and len(isnull(b.kpwybh,''))>0) or ((b.kpwybh=a.kph or b.kph=a.kph ) and len(isnull(b.kph,''))>0)    ) ";
        String sql="select * from uf_gbxtzczmxx a1,( " +
                " select kpwybs,sxrq from( " +
                " select kpwybs,sxrq,ROW_NUMBER() over(partition by kpwybs order by sxrq desc) RowNum from ( \n" +
                //" select  * from uf_gbxtzczmxx a  where isnull(dj,1000)>=1000 and len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0 and len( isnull(sxrq,''))>0 and isnull(kpzt,-1) in (0,1,2,3) and " +
                //" select  * from uf_gbxtzczmxx a  where len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0 and len( isnull(sxrq,''))>0 and isnull(kpzt,-1) in (0,1,2,3) and " +
                " select  * from uf_gbxtzczmxx a  where len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0  and isnull(kpzt,-1) in (0,1,2,3) \n" +
                " and (mldm in ('1030104','1030105','1030107','103060401','103060101','103060102','103060103','103060104','103060199','30105','10204','1030605') \n"+
                " or (mldm in ('103019903','103019904') and gdzcbm not like '%执法记录仪工作站%' and gdzcbm not like '%无盘工作站%')) \n"+
                " and exists (select 1  from uf_swzczmxx b where ((b.kpwybh=a.kpwybs or b.xzgbxtzc=a.kpwybs  or b.xzgbxtzc=a.kpwybs or b.id=a.dyswzc) and len(isnull(b.kpwybh,''))>0) \n" +
                "and isnull(b.zczt,-1) in (0,1,2,4,5,7) )   )  a  ) b where RowNum=1 ) b1 \n" +
                " where a1.kpwybs=b1.kpwybs \n";
                //" where a1.kpwybs=b1.kpwybs and a1.sxrq=b1.sxrq";
        log.writeLog("compareGBToSW_vali "+sql);
        re.execute(sql);
        List<Object> business =new ArrayList<Object>() ;
        List<Map<String, Object>> listMap=new ArrayList<Map<String, Object>>();
        gbzcException gbzcException=null;
        while(re.next()){
            gbzcException=new gbzcException();
            String kpwybs=Util.null2String(re.getString("kpwybs"));//卡片唯一标识
            gbzcException.setKpwybs(kpwybs);
            String kph=Util.null2String(re.getString("kph"));//卡片号
            gbzcException.setKph(kph);
            String mldm=Util.null2String(re.getString("mldm"));//目录代码
            gbzcException.setMldm(mldm);
            String mlmc=Util.null2String(re.getString("mlmc"));//目录名称
            gbzcException.setMlmc(mlmc);
            String gdzcbm=Util.null2String(re.getString("gdzcbm"));//固定资产编码
            gbzcException.setGdzcbm(gdzcbm);
            String gdzcmc=Util.null2String(re.getString("gdzcmc"));//		固定资产名称
            gbzcException.setGdzcmc(gdzcmc);
            String ggxh=Util.null2String(re.getString("ggxh"));//规格型号
            gbzcException.setGgxh(ggxh);
            String pp=Util.null2String(re.getString("pp"));//	品牌
            gbzcException.setPp(pp);
            double dj=Util.getDoubleValue(re.getString("dj"), 0);//单价
            gbzcException.setDj(dj);
            int zcly=Util.getIntValue(re.getString("zcly"),-1);//资产来源
            gbzcException.setZcly(zcly);
            int kpzt=Util.getIntValue(re.getString("kpzt"),-1);//卡片状态
            gbzcException.setKpzt(kpzt);
            String sxrq=Util.null2String(re.getString("sxrq"));//	生效日期
            gbzcException.setSxrq(sxrq);
            String qdrq=Util.null2String(re.getString("qdrq"));//取得日期
            gbzcException.setQdrq(qdrq);
            String jssj=Util.null2String(re.getString("jssj"));//减少时间
            gbzcException.setJssj(jssj);
            int sybm=Util.getIntValue(re.getString("sybm"),-1);//使用部门
            gbzcException.setSybm(sybm);
            int syr=Util.getIntValue(re.getString("syr"),-1);//使用人
            gbzcException.setSyr(syr);
            String cfdd=Util.null2String(re.getString("cfdd"));//存放地点
            gbzcException.setCfdd(cfdd);
            String bz=Util.null2String(re.getString("bz"));//	备注
            gbzcException.setBz(bz);
            String gbzcid=Util.null2String(re.getString("id"));//	关保资产ID
            //if(checkVali(gbzcid)){
            if(!checkVali(kpwybs)){
                log.writeLog("compareGBToSW_vali 卡片唯一标识不存在--->"+kpwybs);
                Object[] param1=new Object[2];
                //需要过滤掉 为 2的情况
                String sql11="update uf_uf_gbxtzczmxxexc  set sfyxz=? where kpwybs=?";
                param1[0]=2;
                param1[1]=kpwybs;
                Map<String,Object> sqlmap1=new HashMap<>();
                sqlmap1.put("sql",sql11);
                sqlmap1.put("params",param1);
                listMap.add(sqlmap1);

                Object[] param2=new Object[2];
                String sql12="update uf_gbxtzczmxx  set sfpk=? where kpwybs=?";
                param2[0]=0;
                param2[1]=kpwybs;
                Map<String,Object> sqlmap2=new HashMap<>();
                sqlmap2.put("sql",sql12);
                sqlmap2.put("params",param2);

                listMap.add(sqlmap2);
                String mess=SwExceptionBaseService.getObjMapList(business,listMap);
                if(!"".equals(mess)){
                    log.writeLog(business.toString());
                }
            }


            //Object[] param2=new Object[2];
            //String sql12="update uf_gbxtzczmxx  set sfpk=? where id=?";
            //param2[0]=1;
            //param2[1]=gbzcid;
            //Map<String,Object> sqlmap2=new HashMap<>();
            //sqlmap2.put("sql",sql12);
            //sqlmap2.put("params",param2);
            //listMap.add(sqlmap2);
            //if(business.size()==max){
            //开始写入

            //清空business
            listMap.clear();
            //}
        }
        if(business.size()>0){
            String mess=SwExceptionBaseService.getObjMapList(business,null);
            if(!"".equals(mess)){
                log.writeLog(mess+"--->"+business.toString());
            }
        }
        setQx();
    }
    /*
        计算 帐实不符率 数据
     */
    public void setZsbfl(){
        //通不过部门遍历  数据
        List<Object> business =new ArrayList<Object>() ;
        uf_gbzcdpBaseService uf_gbzcdpBaseService=new uf_gbzcdpBaseService();
        RecordSet re=new RecordSet();
        RecordSet re1=new RecordSet();
        re1.execute("delete from uf_gbzcdp");//先清空
        String sql="select * from HrmSubCompany  where isnull(canceled,-1) in (0,-1) ";
        re.execute(sql);
        while(re.next()){
            uf_gbzcdp uf_gbzcdp=new uf_gbzcdp();
            String id=Util.null2String(re.getString("id"));
            String subcompanyname=Util.null2String(re.getString("subcompanyname"));
            //0: 不符合 1 符合
            //String sql1="select  count(1) counts,'0' lx from uf_gbxtzczmxx a  where len(isnull(kph,''))>0 and isnull(sybm,0)>0 and sybm="+id+" and " +
                        //" not exists (select 1  from uf_swzczmxx b where (( b.kph=a.kph ) and len(isnull(b.kph,''))>0) and dybm="+id+" ) group by sybm"+
                        //" union all select  count(1) counts,'1' lx from uf_gbxtzczmxx a  where len(isnull(kph,''))>0 and isnull(sybm,0)>0 and sybm="+id+" and " +
                        //"  exists (select 1  from uf_swzczmxx b where (( b.kph=a.kph ) and len(isnull(b.kph,''))>0) and dybm="+id+" ) group by sybm";
            //String sql1="select  count(1) counts,'0' lx from uf_gbxtzczmxx a  where isnull(dj,1000)>=1000 and len(isnull(kpwybs,''))>0 and isnull(sybm,0)>0 and sybm="+id+" and " +
            String sql1=" select count(1) counts ,'0' lx from uf_gbxtzczmxx a1,( \n" +
                    "  select kpwybs,sxrq from( \n" +
                    "  select kpwybs,sxrq,ROW_NUMBER() over(partition by kpwybs order by sxrq desc) RowNum from ( \n" +
                    "  select  * from uf_gbxtzczmxx a  where len(isnull(kpwybs,''))>0 and isnull(sybm,0)>0  and isnull(kpzt,-1) in (0,1,2,3) and len(isnull(a.dyswzc,''))=0  \n" +
                    "  and (mldm in ('1030104','1030105','1030107','103060401','103060101','103060102','103060103','103060104','103060199','30105','10204','1030605') \n" +
                    "  or (mldm in ('103019903','103019904') and gdzcbm not like '%执法记录仪工作站%' and gdzcbm not like '%无盘工作站%')) AND kph NOT LIKE '%57J%' \n" +
                    "  and not exists (select 1  from uf_swzczmxx b where ((b.kpwybh=a.kpwybs or b.xzgbxtzc=a.kpwybs or b.xzgbxtzc=a.kpwybs) and len(isnull(b.kpwybh,''))>0) \n" +
                    " and isnull(b.zczt,-1) in (0,1,2,4,5,7) )     )  a  ) b where RowNum=1 ) b1  \n" +
                    "  where a1.kpwybs=b1.kpwybs and a1.sybm= " +id+
                    "  union all \n" +
                    "  select count(1) counts ,'1' lx from uf_gbxtzczmxx a1,(\n  " +
                    "  select kpwybs,sxrq from(  \n" +
                    "  select kpwybs,sxrq,ROW_NUMBER() over(partition by kpwybs order by sxrq desc) RowNum from (  \n" +
                    "  select  * from uf_gbxtzczmxx a  where len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0  and isnull(kpzt,-1) in (0,1,2,3) \n" +
                    "  and (mldm in ('1030104','1030105','1030107','103060401','103060101','103060102','103060103','103060104','103060199','30105','10204','1030605') \n"+
                    "  or (mldm in ('103019903','103019904') and gdzcbm not like '%执法记录仪工作站%' and gdzcbm not like '%无盘工作站%')) \n"+
                    "  and exists (select 1  from uf_swzczmxx b where ((b.kpwybh=a.kpwybs or b.xzgbxtzc=a.kpwybs  or b.xzgbxtzc=a.kpwybs or b.id=a.dyswzc) \n" +
                    " and len(isnull(b.kpwybh,''))>0) and isnull(b.zczt,-1) in (0,1,2,4,5,7) )   )  a  ) b where RowNum=1 ) b1  \n" +
                    "  where a1.kpwybs=b1.kpwybs  and a1.sybm="+id +
                    " AND a1.kph NOT LIKE '%57J%' \n"+
                    "  union all (select count(id) counts,'2' lx  from uf_gbxtzczmxx where sybm="+id+")";
            //change by  huangwm 2021年5月6日11:21:26
            //String sql1 = "select sybm,count(id) as counts  from uf_uf_gbxtzczmxxexc where sybm="+id+" and (sfyxz is null or sfyxz='') group by sybm order by sybm";
            log.writeLog("setZsbfl 设置账实不符数"+sql1);
            re1.execute(sql1);
            int xfs=0;
            int bfs=0;
            int gbzcs=0;
            while(re1.next()){
                //0 不符数 1 相符数 2 关保资产数
                String lx=Util.null2String(re1.getString("lx")).trim() ;
                if("0".equals(lx)){
                    bfs=Util.getIntValue(re1.getString("counts"),0);
                }else if("1".equals(lx)){
                    xfs=Util.getIntValue(re1.getString("counts"),0);
                }else if("2".equals(lx)){
                    gbzcs=Util.getIntValue(re1.getString("counts"),0);
                }
            }
            uf_gbzcdp.setBm(id);
            uf_gbzcdp.setBfs(bfs);
            uf_gbzcdp.setXfs(xfs);
            uf_gbzcdp.setGbzcs(gbzcs);
            business.add(uf_gbzcdp);

        }
        if(business!=null&&business.size()>0){
            String mess=uf_gbzcdpBaseService.getObjMapList(business,null);
            if(!"".equals(mess)){
                log.writeLog(mess+"--->"+business.toString());
            }
            setQx1();
        }
    }
    /*
        添加默认共享权限
     */
    public void setQx(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                swException swException=new swException();
                RecordSet re=new RecordSet();
                String sql="select * from uf_uf_gbxtzczmxxexc  ";
                re.execute(sql);
                while(re.next()){
                    String id=Util.null2String(re.getString("id")).trim();
                    ModeRightInfo mri=new ModeRightInfo();
                    mri.editModeDataShare(Util.getIntValue(1+"",0),Util.getIntValue(swException.getFormmodeid(),0),Util.getIntValue(id,0));
                }
            }
        }).start();
    }
    /*
       添加默认共享权限
    */
    public void setQx1(){
        new Thread(new Runnable() {
            @Override
            public void run() {
                uf_gbzcdp uf_gbzcdp=new uf_gbzcdp();
                RecordSet re=new RecordSet();
                String sql="select * from uf_gbzcdp  ";
                re.execute(sql);
                while(re.next()){
                    String id=Util.null2String(re.getString("id")).trim();
                    ModeRightInfo mri=new ModeRightInfo();
                    mri.editModeDataShare(Util.getIntValue(1+"",0),Util.getIntValue(uf_gbzcdp.getFormmodeid(),0),Util.getIntValue(id,0));
                }
            }
        }).start();
    }
    /*
      初始化数据
   */
    public void iniDate(){
        //RecordSet re=new RecordSet();
        //re.execute("delete from uf_uf_gbxtzczmxxexc");
    }
    /*
        判断是否已经存在
     */
    public boolean  checkVali(String gbzcid){
        RecordSet re=new RecordSet();
        String sql="select *　from　uf_uf_gbxtzczmxxexc　where　kpwybs='"+gbzcid+"'";
        re.execute(sql);
        if(re.next()){
            return true;
        }else{
            return false;
        }
    }

    /**
     * 获取关保资产需要写入关保异常表的数据 huangwm
     * @return
     */
    public List<String> getGbzcyc(){
        List<String> list = new ArrayList<>();
        RecordSet rs = new RecordSet();
        log.writeLog("获取关保资产需要写入关保异常表的数据 huangwm");
        String sql="select * from uf_gbxtzczmxx a1,( \n" +
                " select kpwybs,sxrq from( \n" +
                " select kpwybs,sxrq,ROW_NUMBER() over(partition by kpwybs order by sxrq desc) RowNum from ( \n" +
                //" select  * from uf_gbxtzczmxx a  where isnull(dj,1000)>=1000 and len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0 and len( isnull(sxrq,''))>0 and isnull(kpzt,-1) in (0,1,2,3) and len(isnull(a.dyswzc,''))=0 and" +
                //" select  * from uf_gbxtzczmxx a  where len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0 and len( isnull(sxrq,''))>0 and isnull(kpzt,-1) in (0,1,2,3) and len(isnull(a.dyswzc,''))=0 and" +
                " select  * from uf_gbxtzczmxx a  where len(isnull(kpwybs,'')+isnull(kph,''))>0 and isnull(sybm,0)>0  and isnull(kpzt,-1) in (0,1,2,3) and len(isnull(a.dyswzc,''))=0 \n" +
                " and (mldm in ('1030104','1030105','1030107','103060401','103060101','103060102','103060103','103060104','103060199','30105','10204','1030605') \n"+
                " or (mldm in ('103019903','103019904') and gdzcbm not like '%执法记录仪工作站%' and gdzcbm not like '%无盘工作站%')) \n"+
                " or (mldm in ('1030106') and gdzcbm not like '%终端%' and gdzcbm not like '%电子%' and gdzcbm not like '%执法%' ) "+//增加1030106的写入盘亏
                " and not exists (select 1  from uf_swzczmxx b where ((b.kpwybh=a.kpwybs or b.xzgbxtzc=a.kpwybs or b.xzgbxtzc=a.kpwybs) and len(isnull(b.kpwybh,''))>0) \n" +
                " and isnull(b.zczt,-1) in (0,1,2,3,4,5,7) )     )  a  ) b where RowNum=1 ) b1 \n" +
                " where a1.kpwybs=b1.kpwybs "+
                " AND a1.kph NOT LIKE '%57J%' ";//对碰时去掉缉私局和事业单位的 huangwm 2022年9月14日10:19:52
        log.writeLog("getGbzcyc-->>"+sql);
        rs.execute(sql);
        int updateCount2 = 0;
        RecordSet rs2 = new RecordSet();
        RecordSet rs3 = new RecordSet();
        while (rs.next()){
            String kpwybs = rs.getString("kpwybs");
            list.add(kpwybs);
            //针对已经通过销账功能关联了实物的关保资产，后有删除实物资产时解除关联   需要重新更新为盘亏
            rs2.execute("select glswzc,dyswzc,kpwybs from uf_gbxtzczmxx where kpwybs='"+kpwybs+"'");
            if (rs2.next()){
                String glswzc = rs2.getString(1);
                String dyswzc = rs2.getString(2);
                if(glswzc.equals("0") || glswzc.equals("") || dyswzc.equals("0") || dyswzc.equals("")){
                    updateCount2++;
                    boolean upGbyc2 =  rs3.execute("update uf_uf_gbxtzczmxxexc set sfyxz = 1 where gbzcid='"+kpwybs+"'");
                    if(upGbyc2){
                        log.writeLog("更新关保异常数据为盘亏成功"+kpwybs);
                    }else{
                        log.writeLog("更新关保异常数据为盘亏失败"+kpwybs);
                    }
                }
            }
        }
        log.writeLog("需要写入关保对碰异常表的数据有"+list.size()+"条,更新已处理"+updateCount2+"条");
        return list;
    }

    /**
     * 根据需要写入关保异常表数据来判断更新关保异常表数据 huwngwm
     */
    public void updateGbyc(){
        RecordSet rs = new RecordSet();
        RecordSet up = new RecordSet();
        log.writeLog("=================更新关保异常表数据开始====================");
        List<String> getGbzcyc = getGbzcyc();
        rs.execute("select gbzcid,gbbid,kph,kpwybs from uf_uf_gbxtzczmxxexc");
        log.writeLog("现关保异常表有数据"+rs.getCounts()+"条");
        int updateCount1 = 0;

        while (rs.next()){
            String gbzcid = rs.getString("gbzcid");
            if(!getGbzcyc.contains(gbzcid)){
                updateCount1++;
                log.writeLog("关保异常表中["+gbzcid+"]不需要再计入对碰盘亏");
                boolean upGbyc = up.execute("update uf_uf_gbxtzczmxxexc set sfyxz=2,sfpk=1 where gbzcid='"+gbzcid+"'");
                if(upGbyc){
                    log.writeLog("更新关保异常数据为已处理成功"+gbzcid);
                }else{
                    log.writeLog("更新关保异常数据为已处理失败"+gbzcid);
                }
            }
        }
        log.writeLog("=================更新关保异常表数据结束,更新已处理"+updateCount1+"条===================" );
    }

    /**
     * 更新关保异常表的卡片号 由于关保资产调拨，卡片好会更新 需要同步更新异常表中的卡片号 huangwm
     */
    public  void updateGbycKph(){

    }
}
